package com.github.pig.admin.service.repair.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.github.pig.admin.mapper.repair.RepairRecordMapper;
import com.github.pig.admin.model.entity.SysRole;
import com.github.pig.admin.model.repair.RepairRecord;
import com.github.pig.admin.model.repair.RepairRecordWhere;
import com.github.pig.admin.service.repair.IRepairRecordService;
import com.github.pig.admin.util.AjaxJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 报修记录表 服务实现类
 * </p>
 *
 * @author lxm
 * @since 2018-06-27
 */
@Service
public class RepairRecordServiceImpl extends ServiceImpl<RepairRecordMapper, RepairRecord> implements IRepairRecordService {

    @Autowired
    private RepairRecordMapper repairRecordMapper;
    @Override
    public Page selectRepairCordDataGrid(Page<RepairRecord> page, RepairRecordWhere repairRecordWhere) {
        List<RepairRecord> result = repairRecordMapper.selectRepairCordDataGrid(page,repairRecordWhere);
        page.setRecords(result);
        return page;
    }

    @Override
    public List<SysRole> getRoleListByCommunityId(String id) {
        return repairRecordMapper.getRoleListByCommunityId(id);
    }

    @Override
    public AjaxJson selectRepairCordDataGrid(RepairRecordWhere repairRecordWhere){

        // 定义报修已提交总数sumRepair
        Integer sumRepair ;
        AjaxJson json = new AjaxJson();
        try {
            List<RepairRecord> list = repairRecordMapper.selectRepairCordDataGrid(repairRecordWhere);
            sumRepair = list.size();

            json.setObj(sumRepair);
            json.setSuccess(true);
            json.setMsg("获取报修已提交总数成功");
        }catch (Exception e){
            json.setMsg("获取报修已提交总数失败");
            json.setSuccess(false);
        }

        return json;
    }

    }

